package com.zhz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhz.domain.Config;
import com.zhz.mapper.ConfigMapper;
import com.zhz.service.ConfigService;
import org.springframework.util.StringUtils;

/**
 * @author ：zhz
 * @date ：Created in 2020/12/20
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 * @description:
 **/
@Service
public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> implements ConfigService {

    /**
     * 条件分页查询参数列表
     *
     * @param page
     * @param type
     * @param code
     * @param name
     * @return
     */
    @Override
    public Page<Config> findByPage(Page<Config> page, String type, String code, String name) {
        return page(page, new LambdaQueryWrapper<Config>()
                .like(StringUtils.isEmpty(type), Config::getType, type)
                .like(StringUtils.isEmpty(code), Config::getCode, code)
                .like(StringUtils.isEmpty(name), Config::getName, name)
        );
    }

    /**
     * 通过规则的CODE查询签名
     *
     * @param code 签名的code
     * @return config的值
     */
    @Override
    public Config getConfigByCode(String code) {
        return getOne(new LambdaQueryWrapper<Config>()
                .eq(Config::getCode, code)
        );
    }
}
